package org.camunda.bpm.getstarted.loanapproval.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationContextUtils implements ApplicationContextAware {
    private static ApplicationContext context;

    public ApplicationContextUtils() {
    }

    public static ApplicationContext getApplicationContext() {
        return context;
    }

    public static <T> List<T> getBeansByClass(Class<T> c) {
        Map<String, T> map = getApplicationContext().getBeansOfType(c);
        List<T> beans = new ArrayList();
        Iterator var3 = map.entrySet().iterator();

        while(var3.hasNext()) {
            Entry<String, T> entry = (Entry)var3.next();
            beans.add(entry.getValue());
        }

        return beans;
    }

    public static <T> T getBeanByClass(Class<T> c) {
        Map<String, T> map = getApplicationContext().getBeansOfType(c);
        List<T> beans = new ArrayList();
        Iterator var3 = map.entrySet().iterator();

        while(var3.hasNext()) {
            Entry<String, T> entry = (Entry)var3.next();
            beans.add(entry.getValue());
        }

        return beans.get(0);
    }

    public static String getProperty(String propertyName) {
        String propertyValue = context.getEnvironment().getProperty(propertyName);
        return propertyValue;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
}